<?php

class Groups {

    private $_ID;
    private $_name;
    private $_description;
    private $_createdDate;
    private $_modifiedDate;
    private $_createdUserID;
    private $_modifiedUserID;
    private $_createdUser;
    private $_modifiedUser;
    private $_visable;

    public function getVisable() {
        return $this->_visable;
    }

    public function setVisable($visable) {
        $this->_visable = $visable;
    }

    public function getID() {
        return $this->_ID;
    }

    public function setID($ID) {
        $this->_ID = $ID;
    }

    public function getName() {
        return $this->_name;
    }

    public function setName($name) {
        $this->_name = $name;
    }

    public function getDescription() {
        return $this->_description;
    }

    public function setDescription($description) {
        $this->_description = $description;
    }

    public function getCreatedDate() {
        return $this->_createdDate;
    }

    public function setCreatedDate($createdDate) {
        $this->_createdDate = $createdDate;
    }

    public function getModifiedDate() {
        return $this->_modifiedDate;
    }

    public function setModifiedDate($modifiedDate) {
        $this->_modifiedDate = $modifiedDate;
    }

    public function getCreatedUserID() {
        return $this->_createdUserID;
    }

    public function setCreatedUserID($createdUserID) {
        $this->_createdUserID = $createdUserID;
    }

    public function getModifiedUserID() {
        return $this->_modifiedUserID;
    }

    public function setModifiedUserID($modifiedUserID) {
        $this->_modifiedUserID = $modifiedUserID;
    }

    public function getCreatedUser() {
        return $this->_createdUser;
    }

    public function setCreatedUser($createdUser) {
        $this->_createdUser = $createdUser;
    }

    public function getModifiedUser() {
        return $this->_modifiedUser;
    }

    public function setModifiedUser($modifiedUser) {
        $this->_modifiedUser = $modifiedUser;
    }

    private function setGroup($object, $row) {
        $object->setID($row->G_ID);
        $object->setName($row->G_Name);
        $object->setDescription($row->G_Description);
        $object->setCreatedDate($row->G_CreatedDate);
        $object->setModifiedDate($row->G_ModifiedDate);
        $object->setCreatedUserID($row->G_CreatedUserID);
        $object->setModifiedUserID($row->G_ModifiedUserID);
        $object->setVisable($row->G_Visable);
        return $object;
    }

    public function getByID($db = null) {
        if ($db != null) {
            $sql = 'SELECT
                        `G_ID`,
                        `G_Name`,
                        `G_Description`,
                        `G_CreatedDate`,
                        `G_ModifiedDate`,
                        `G_CreatedUserID`,
                        `G_ModifiedUserID`,
                        `G_Visable`
                      FROM `groups`
                      WHERE G_ID = :G_ID;';

            $parameters = array(':G_ID');
            $values = array($this->getID());
            $types = array(PDO::PARAM_INT);

            $result = $db->executeQuery($sql, $parameters, $values, $types);

            if ($result != null) {
                $row = $result->fetch();
                return $this->setGroup($this, $row);
            } else {
                return null;
            }
        }
    }

    public function getList($db = null) {
        if ($db != null) {
            $sql = 'SELECT
                        `G_ID`,
                        `G_Name`,
                        `G_Description`,
                        `G_CreatedDate`,
                        `G_ModifiedDate`,
                        `G_CreatedUserID`,
                        `G_ModifiedUserID`,
                        `G_Visable`
                      FROM `groups`
                      ORDER BY G_ID DESC';
            $parameters = null;
            $values = null;
            $types = null;

            $result = $db->executeQuery($sql, $parameters, $values, $types);

            if ($result != null) {
                $rows = array();
                while ($row = $result->fetch()) {
                    $group = new Groups();
                    $group=  $this->setGroup($group, $row);                    
                    $rows[] = $group;
                }
                return $rows;
            } else {
                return null;
            }
        }
    }

}

?>
